package com.situ.day9;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentManager {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		ArrayList<Student> list = new ArrayList<Student>();
		while (true) {
			System.out.println("请输入学生的id：");
			int id = scanner.nextInt();
			System.out.println("请输入学生的名字：");
			String name = scanner.next();
			System.out.println("请输入学生的年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入学生的班级：");
			String className = scanner.next();

			Student student = new Student(id, name, age, className);
			list.add(student);

			System.out.println("是否退出(0退出，任意键继续):");
			int quit = scanner.nextInt();
			if (quit == 0) {
				break;

			}
		}

		for (Student student : list) {
			System.out.println(student);
		}

		// for(;;)
		while (true) {
			System.out.println("----------------------");
			System.out.println("根据id查找输入：1");
			System.out.println("根据名字查找输入：2");
			System.out.println("根据年龄查找输入：3");
			System.out.println("根据班级查找输入：4");
			System.out.println("退出程序：0");
			System.out.println("----------------------");
			int type = scanner.nextInt();
			if (type == 0) {
				System.out.println("退出程序");
				break;
			}

			switch (type) {
			case 1:// 根据id查找
				System.out.println("根据id搜索");
				System.out.println("请输入学生id：");
				int searchId = scanner.nextInt();
				// 查找数组里面学生的名字是不是有要和搜索的名字一样，
				// 1、如果有就打印当前学生的信息，
				// 2、如果搜索完了所有学生都没有找到，打印“没有该姓名的学生”
				boolean isSearchByIdFound = false;
				for (Student student : list) {
					if (searchId == student.getId()) {
						isSearchByIdFound = true;
						System.out.println(student);
					}
				}
				if (isSearchByIdFound == false) {
					System.out.println("没有该姓名学生");
				}
				break;
			case 2:// 根据名字查找
				System.out.println("根据名字搜索");
				System.out.println("请输入学生姓名：");
				String searchName = scanner.next();
				boolean isSearchByNameFound = false;
				for (Student student : list) {
					if (searchName.equals(student.getName())) {
						isSearchByNameFound = true;
						System.out.println(student);
					}
				}
				if (isSearchByNameFound == false) {
					System.out.println("没有该姓名学生");
				}
				break;
			case 3:// 根据年龄查找
				System.out.println("根据年龄搜索");
				System.out.println("请输入学生年龄：");
				int searchAge = scanner.nextInt();
				boolean isSearchByAgeFound = false;
				for (Student student : list) {
					if (searchAge == student.getAge()) {
						isSearchByAgeFound = true;
						System.out.println(student);
					}
				}
				if (isSearchByAgeFound == false) {
					System.out.println("没有该姓名学生");
				}
				break;
			case 4:// 根据班级查找
				System.out.println("根据班级搜索");
				System.out.println("请输入学生班级：");
				String searchclassName = scanner.next();
				boolean isSearchByclassNameFound = false;
				for (Student student : list) {
					if (searchclassName.equals(student.getClassName())) {
						isSearchByclassNameFound = true;
						System.out.println(student);
					}
				}
				if (isSearchByclassNameFound == false) {
					System.out.println("没有该姓名学生");
				}
				break;
			default:
				break;
			}
		}

	}
}
